package com.prp.gwt.client.widgets.user.friend;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.History;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.HorizontalPanel;
import com.google.gwt.user.client.ui.Image;
import com.google.gwt.user.client.ui.VerticalPanel;
import com.prp.gwt.client.user.friend.FriendListener;
import com.prp.gwt.client.user.php.PHPHistoryHandler;
import com.prp.gwt.client.vo.User;

public class InvitationItem extends HorizontalPanel{

	private User user;
	
	public InvitationItem(User user){
		this.user = user;
		setSpacing(8);
		Image portrait = new Image(user.getPortrait());
		portrait.setWidth("50px");
		add(portrait);
		addOperationPanel();
	}
	
	private void addOperationPanel(){
		VerticalPanel vPanel = new VerticalPanel();
		HTML userName = new HTML("<a>"+user.getUsername()+"</a>");
		userName.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				History.newItem(PHPHistoryHandler.PREFIX_USERHOME+user.getId());
			}
		});
		vPanel.add(userName);
		userName.addStyleName("invitation-item-text");
		HTML buildup = new HTML("<a>接受邀请</a>");
		buildup.addStyleName("invitation-item-text");
		vPanel.add(buildup);
		HTML cancel = new HTML("<a>忽略</a>");
		cancel.addStyleName("invitation-item-text");
		vPanel.add(cancel);
		add(vPanel);
		buildup.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				FriendListener.getInstance().buildup(user);
			}
		});
		cancel.addClickHandler(new ClickHandler(){
			@Override
			public void onClick(ClickEvent event) {
				FriendListener.getInstance().cancelInvite(user.getId());
			}
		});
	}
	
}
